package com.zhuss.product.processor;

import java.util.Date;

import com.zhuss.enums.StartStopEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.product.hotLine.StopHotLineBo;
import com.zhuss.bean.vo.product.hotLine.DetailHotLineVo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.product.db.dao.ext.HotLineDao;
import com.zhuss.product.db.entity.HotLine;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.DzcxException;
import com.zhuss.exception.ExceptionCode;
import com.zhuss.util.JsonUtil;

/**
 * 创建热门线路 processor
 * @Author: zhushanshuo
 * @Date: Mon Jan 11 09:20:35 CST 2021
 */
@Component("hotLineStop")
public class HotLineStop extends AbstractProcessor<Object, StopHotLineBo> implements Processor<Object, StopHotLineBo> {

    @Autowired
    private HotLineDao hotLineDao;
    
    @Autowired
	@Qualifier("hotLineRead")
	private HotLineRead hotLineRead;
    
    @Autowired
    private HotLineCheck hotLineCheck;
    
    /**
     * 校验
     */
    @Override
    public void check(StopHotLineBo bo) throws DzcxException {
    	// 当前热门线路不满足停用条件
//		if (!hotLineCheck.checkStop(bo.getHotLineId())) {
//			throw new DzcxException(ExceptionCode.当前热门线路不满足停用条件);
//		}
    }
    
    /**
     * 操作方法
     * @throws DzcxException 
     */
    @Override
    public Object process(StopHotLineBo param) throws DzcxException {
    	
    	Long hotLineId = param.getHotLineId();
    	
    	HotLine record = new HotLine();
    	record.setHotLineId(param.getHotLineId());
		record.setStatus(StartStopEnum.停用.key());
    	
    	record.setModifierId(param.getConcurrentUserId());
    	record.setModifier(param.getConcurrentUserName());
    	record.setModifyTime(new Date());
    	hotLineDao.updateByPrimaryKeySelective(record);
    	
    	String name = ((DetailHotLineVo) hotLineRead.detail(hotLineId)).getName();
    	
    	param.setName(name);
        return null;
    }
    
    /**
     * 操作日志
     */
	@Override
	public Object log(StopHotLineBo param) throws DzcxException {
		OpLog record = new OpLog();
    	record.setMoudle(MoudleEnum.商品.key());
    	record.setAction(LogActionEnum.热门线路停用.key());
    	record.setTargetId(param.getHotLineId());
    	record.setTargetName(param.getName());
    	record.setContent("参数: " + JsonUtil.toJson(param));
    	record.setReason(param.getExceptionReason());
    	
    	record.setCreatorId(param.getConcurrentUserId());
    	record.setCreator(param.getConcurrentUserName());
    	record.setCreateTime(new Date());
    	log(record);
    	return null;
	}
}
